﻿using System.Runtime.Serialization;
using GMME.Model.Rtm.Result;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm.Notify
{
    [DataContract]
    public class RtmChannelPlayerPropertiesNotify
    {
        /**
         * 开发者传入的频道Id
         */
        [DataMember(Name = "channelId")]
        [Preserve]
        public string ChannelId { get; set; }

        [DataMember(Name = "playerInfo")] public RtmChannelMemberInfo PlayerInfo { get; set; }

#if UNITY_ANDROID
        internal static RtmChannelPlayerPropertiesNotify ConvertRtmChannelPlayerPropertiesNotify(
            AndroidJavaObject javaObject)
        {
            if (javaObject != null)
            {
                RtmChannelPlayerPropertiesNotify rtmChannelPlayerPropertiesNotify = new();
                rtmChannelPlayerPropertiesNotify.ChannelId = javaObject.Call<string>("getChannelId");
                var androidJavaObject = javaObject.Call<AndroidJavaObject>("getPlayerInfo");
                rtmChannelPlayerPropertiesNotify.PlayerInfo =
                    RtmChannelMemberInfo.ConvertRtmChannelMemberInfo(androidJavaObject);
                return rtmChannelPlayerPropertiesNotify;
            }

            return null;
        }

#endif

        [Preserve]
        public void SetPlayerProperties()
        {
            if (PlayerInfo != null) PlayerInfo.ConvertPropertiesToDict();
        }
    }
}